<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="896" @ok="handleSubmit">
      <BasicForm @register="registerForm">

        <template #diySlot="{ model, field }">
            <div style="width:868px;" class="diyBox">
              <div class="row" >
                  <div class="flex1" style="height:104px;">项目</div>
                  <div class="flex5" style="height:104px;">人民币与港币的汇率:{{model.monRate}}</div>
                  <div class="flex4" style="height:104px;">
                    <div  class="flex" style="width:100%;border-bottom: 1px solid #d9d9d9;">本项应收</div>
                    <div  class="flex" style="width:50%;border-right: 1px solid #d9d9d9;">人民币金额</div>
                    <div  class="flex" style="width:50%;">折港币金额</div>
                  </div>
              </div>

               <div class="row">
                  <div class="flex1" style="height:104px">管理费</div>
                  <div class="flex5" style="height:104px">
                    <div  class="flex" style="width:30%;border-right: 1px solid #d9d9d9;border-bottom: 1px solid #d9d9d9;">工人劳务管理费</div>
                    <div  class="flex" style="width:70%;border-bottom: 1px solid #d9d9d9;"> {{model.grs}}*{{model.grgl}} = {{fmoney(model.c1)}}({{model.pz1}})</div>
                    <div  class="flex" style="width:30%;border-right: 1px solid #d9d9d9;">工厂综合管理费</div>
                    <div  class="flex" style="width:70%;"> {{model.cfgl}}*{{model.cfmj}}={{fmoney(model.c2)}}({{model.pz2}})</div>
                  </div>
                  <div class="flex2" style="height:104px">
                    <div class="flex" style="width:100%;border-bottom: 1px solid #d9d9d9;">{{fmoney(model.c1?(model.pz1=='人民币'?model.c1:model.c1*model.monRate).toFixed(2):0)}}</div>
                    <div class="flex" style="width:100%;border-bottom: 1px solid #d9d9d9;">{{fmoney(model.c2?(model.pz2=='人民币'?model.c2:model.c2*model.monRate).toFixed(2):0)}}</div>
                  </div>
                   <div class="flex2" style="height:104px">
                    <div class="flex" style="width:100%;border-bottom: 1px solid #d9d9d9;">{{fmoney(model.c1? (model.pz1=='人民币'?model.c1/model.monRate:model.c1).toFixed(2) : 0)}}</div>
                     <div class="flex" style="width:100%;border-bottom: 1px solid #d9d9d9;">{{fmoney(model.c2? (model.pz2=='人民币'?model.c2/model.monRate:model.c2).toFixed(2) : 0)}}</div>
                  </div>
              </div>
              <div class="row">
                  <div class="flex1">外汇补差</div>
                  <div class="flex5">{{model.wfbc}}*{{model.jfbz}}={{fmoney(model.c3)}}({{model.pz3}})</div>
                  <div class="flex2">{{fmoney(model.c3?(model.pz3=='人民币'?model.c3:model.c3*model.monRate).toFixed(2):0)}}</div>
                  <div class="flex2">{{fmoney(model.c3? (model.pz3=='人民币'?model.c3/model.monRate:model.c3).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                <div class="flex1">厂租</div>
                <div class="flex5">{{model.cfzj}}*{{model.jfmj}}={{fmoney(model.c4)}}({{model.pz4}})</div>
                <div class="flex2">{{fmoney(model.c4?(model.pz4=='人民币'?model.c4:model.c4*model.monRate).toFixed(2):0)}}</div>
                <div class="flex2">{{fmoney(model.c4?(model.pz4=='人民币'?model.c4/model.monRate:model.c4).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                  <div class="flex1">其他费用</div>
                  <div class="flex5">{{fmoney(model.qtfy)}}元({{model.pzQt}})</div>
                  <div class="flex2">{{fmoney(model.qtfy?(model.pzQt=='人民币'?model.qtfy:model.qtfy*model.monRate).toFixed(2):0)}}</div>
                  <div class="flex2">{{fmoney(model.qtfy? (model.pzQt=='人民币'?model.qtfy/model.monRate:model.qtfy).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                  <div class="flex1">滞纳金</div>
                  <div class="flex5">{{fmoney(model.znj)}}元(人民币)</div>
                  <div class="flex2">{{fmoney(model.znj)}}</div>
                  <div class="flex2">{{fmoney(model.znj? (model.znj/model.monRate).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                  <div class="flex1">合计</div>
                  <div class="flex5">{{fmoney(model.qkje)}}元(人民币)</div>
                  <div class="flex2">{{fmoney(model.qkje?model.qkje:0)}}</div>
                  <div class="flex2">{{fmoney(model.qkje? (model.qkje/model.monRate).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                  <div class="flex6">应&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;收&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;累&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;计</div>
                  <div class="flex2">{{fmoney(model.qkje ? model.qkje : 0)}}</div>
                  <div class="flex2">{{fmoney(model.qkje? (model.qkje/model.monRate).toFixed(2) : 0)}}</div>
              </div>
              <div class="row">
                  <div class="flex1">已收</div>
                  <div class="flex5">(大写):{{model.bigNum}}</div>
                  <div class="flex2">{{fmoney(model.skje ? model.skje : 0)}}</div>
                  <div class="flex2">{{fmoney(model.skje ? (model.skje/model.monRate).toFixed(2) : 0)}}</div>
              </div>
            </div>
        </template>
        <template #diy2Slot="{ model, field }">
        </template>
         <!-- <template #grs="{ model, field }">
            <a-input-number v-model:value="model[field]" type="InputNumber" @change="c1" defaultValue="0"  placeholder="请输入工人数" dynamicDisabled="false"/>
          </template>
          <template #grglSlot="{ model, field }">
            <a-input-number v-model:value="model[field]" type="InputNumber" @change="c1"  defaultValue="0" :precision=2  placeholder="请输入工人行政费" />
          </template>

        <template #cfglSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c2"  defaultValue="0" :precision=2  placeholder="请输入综合管理费" />
        </template>
        <template #cfmjSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c2"  defaultValue="0" :precision=2  placeholder="请输入厂房面积" />
        </template>

        <template #wfbcSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c3"  defaultValue="0" :precision=2  placeholder="请输入外汇补差" />
        </template>
        <template #jfbzSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c3"  defaultValue="0" :precision=2  placeholder="请输入计费标准" />
        </template>

        <template #cfzjSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c4"  defaultValue="0" :precision=2  placeholder="请输入厂房租金" />
        </template>
        <template #jfmjSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="c4"  defaultValue="0" :precision=2  placeholder="请输入计费面积" />
        </template>

        <template #skjeSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="calculateExt"  defaultValue="0" :precision=2  placeholder="请输入收款金额!" />
        </template>

        <template #qtfySlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="calculateExt"  defaultValue="0" :precision=2  placeholder="请输入其它费用!" />
        </template>-->
<!--        <template #skjeSlot="{ model, field }">
          <a-input-number v-model:value="model[field]" type="InputNumber" @change="calculateExt"  defaultValue="0" :precision=2  placeholder="请输入收款金额!" />
        </template>-->
<!--        <template #billtypeSlot="{model,field}">
        <a-select v-model:value="model[field]"  @change="updatQk" placeholder="请选择收款类别">
          <a-select-option value="租金">租金</a-select-option>
          <a-select-option value="土地使用补偿款">土地使用补偿款</a-select-option>
        </a-select>
        </template>-->

        <template #skqxSlot="{model,field}">
          <a-date-picker v-model:value="model[field]" :disabled="isUpdate" @change="updatQk" placeholder="请选择收款时间" valueFormat="YYYY-MM-DD" require default />
        </template>

      </BasicForm>
  </BasicModal>
</template>

<script lang="ts" setup>
    import {ref, computed, unref,filters} from 'vue';
    import {BasicModal, useModalInner} from '/@/components/Modal';
    import {BasicForm, useForm} from '/@/components/Form/index';
    import {formSchema} from '../DbHire.data';
    import {saveOrUpdate} from '../DbHire.api';
    import {defHttp} from "/@/utils/http/axios";
    import {api} from "/@/views/assets/leaseContract/DbHtb.api";
    import {list} from "/@/views/assets/currency/Tblrate.api";
    import {apiGlfsc} from "/@/views/assets/accountReceivable/DbGlfsc.api";
    import {useUserStore} from "/@/store/modules/user";
    import {useMessage} from "/@/hooks/web/useMessage";
    import { getUserDeparts, selectDepart } from '/@/views/system/depart/depart.api';
    import {getTenantById} from "/@/views/system/tenant/tenant.api";

    const userStore = useUserStore();
    // Emits声明
    const emit = defineEmits(['register','success']);
    const isUpdate = ref(true);

    //表单配置
    const { createMessage } = useMessage();
    const [registerForm, {setProps,resetFields, setFieldsValue, validate,updateSchema,getFieldsValue}] = useForm({
        labelWidth: 160,
        schemas: formSchema,
        showActionButtonGroup: false,
        baseColProps: {span: 12}
    });

    const fmoney=(s,n)=>{
      if(s == '' || s == null || s == undefined | isNaN(Number(s))){
        return s
      }
      s = Number(s) ? Number(s) : s
      s = Math.round(s);
      return fmoney1(s,n);
    }

    const fmoney1=(s,n)=>{
      if(s == '' || s == null || s == undefined | isNaN(Number(s))){
        return s
      }
      s = Number(s) ? Number(s) : s
      n = ((n || n == 0) && n > -1 && n <= 20) ? n : 2;
      s = parseFloat((s + "").replace(/[^\d\.-]/g,"")).toFixed(n) + "" ;
      var l = s.split(".")[0].split("").reverse();
      var r = s.split(".")[1];
      var t = "";
      for(var i = 0;i < l.length;i++){
        t += l[i] + ((i+1)%3 ==0 && (i + 1) != l.length ? "," : "");
      }
      if(n>0){
        r ='.' + r
      }else if(n == 0){
        r=''
      }
      let returnT = t.split("").reverse().join("") + r;
      //负数处理
      if(returnT[0] == '-' && returnT[1] == ','){
        returnT = '-' + returnT.substring(2)
      }
      return returnT;
    }

    function getMonRate(){
        function add0(m) {
          return m < 10 ? '0' + m : m
        }
        var time = new Date()
			  var y = time.getFullYear()
			  var m = add0(time.getMonth() + 1) 
        return list({
          datein: `${y}-${m}`
        }).then(res=>{
          try {
            let monRate = res.records[0].rate
            console.log(monRate);
            setFieldsValue({
              monRate
            })
          } catch (error) {
            
          }
        })
    }


    function setRound(e){
      if(e!)
        return 0;
      let temp = Math.round(e*100) / 100;
        return temp.toFixed(0)
    }
    /**
     * @param startDate  开始日期 yyyy-MM-dd
     * @param enDate  结束日期 yyyy-MM-dd
     * @returns {number} 两日期相差的天数
     */
    function getDaysBetween(startDate, enDate) {
      const sDate = Date.parse(startDate)
      const eDate = Date.parse(enDate)
      if (sDate > eDate) {
        return 0
      }
      // 这个判断可以根据需求来确定是否需要加上
      if (sDate === eDate) {
        return 0
      }
      const days = (eDate - sDate) / (1 * 24 * 60 * 60 * 1000)
      return days
    }
    function formaData(timer) {
      const year = timer.getFullYear()
      const month = timer.getMonth() + 1 // 由于月份从0开始，因此需加1
      const day = timer.getDate()
      const hour = timer.getHours()
      const minute = timer.getMinutes()
      const second = timer.getSeconds()
      return `${pad(year, 4)}-${pad(month)}-${pad(day)}`
    }
    function pad(timeEl, total = 2, str = '0') {
      return timeEl.toString().padStart(total, str)
    }
    // 默认使用逗号分割
    function numSplit(num){
      var result = [],decimal="";
      let newNum = num.toString();
      //判断是否是小数
      if(newNum.indexOf(".") != -1){
        decimal = newNum.slice(newNum.indexOf("."));
        newNum = newNum.slice(0, newNum.indexOf("."))
      }
      var length = newNum.length;
      for (let index = 0; index < length; index+=3) {
        if(newNum.length>3){
          result.unshift(`${newNum.slice(-3)}`);
          newNum = newNum.slice(0,newNum.length-3);
        }else{
          result.unshift(newNum)
        }
      }

      return result.join()+decimal;
    }


    function updatQk(e){
      let fv = getFieldsValue();
      let params = {htbh:fv.htbh,qymc:fv.qymc,sfyf:fv.sfyf};
      updateGlfsc(fv,params);
    }

    function getTdbill(fv){
      let grs = fv.grs?fv.grs:0;
      let grgl = fv.grgl?fv.grgl:0;
      let cfgl = fv.cfgl?fv.cfgl:0;
      let cfmj = fv.cfmj?fv.cfmj:0;
      let wfbc = fv.wfbc?fv.wfbc:0;
      let jfbz = fv.jfbz?fv.jfbz:0;
      let gsum = grs*grgl;
      if(fv.pz1=="港币")
        gsum = gsum*fv.monRate;
      let csum = cfgl*cfmj;
      if(fv.pz2=="港币")
        csum = csum * fv.monRate;
      let wsum = fv.wfbc*fv.jfbz;
       if(fv.pz3=="港币")
         wsum = wsum*fv.monRate;


      let qtfy = fv.qtfy?fv.qtfy:0;
      if(fv.pzQt=="港币")
        qtfy = qtfy*fv.monRate;

      return gsum+csum+wsum+qtfy;
    }
    function getQx(sfyf){
      let nd = new Date();
      nd.setDate(16);
      nd.setFullYear(sfyf.split("-")[0]);
      nd.setMonth(sfyf.split("-")[1]-1);
      return formaData(nd);
    }

    function getZnj(qkje,scale,skqx,qx){
      console.log(scale,qx,skqx)
      let between =getDaysBetween(qx,skqx);
      console.log(between);
      if(between==0)return 0;
      let znj = qkje*scale/100*between;
      console.log(scale,znj)
      return znj;
    }


    const updateGlfsc=(fv,params)=>{

      const res =  defHttp.get({url: apiGlfsc.list,params });
      res.then((data)=>{
        console.log(data);
        if(data && data.records && data.records.length==1){
          const glfsc = data.records[0];
          setGlfsc(glfsc);
        }else{
          createMessage.error("请检查企业名称，计收月份，合同编号是否正确或者请先填写相关的计划收款数据");
          resetGlfsc();
        }
        //calculateAll();
      });
    };
    const resetGlfsc = () =>{
      setFieldsValue({
        grs:0,
        grgl:0,
        cfgl:0,
        cfmj:0,
        wfbc:0,
        jfbz:0,
        cfzj:0,
        jfmj:0,
        qtfy:0,
        qkje:0,
        skje:0,
        qkye:0,
        c1:0,
        c2:0,
        c3:0,
        c4:0,
        znj:0,
        znjbl:0,
        hznj:0,
      });
    };
    // const conc1 = computed(()=>{
    //   console.log("tses");
    //   const fv = getFieldsValue();
    //   console.log(fv);
    //   console.log(fv.grs*fv.grg1);
    //   return fv.grs*fv.grg1;
    // });


function setGlfsc(glfsc) {
  let obj = getFieldsValue();

  let skje = obj.skje?obj.skje:0;
  let skqx = "";
  let qx="";
  let znj=0;
  let qkje=0;
  console.log(glfsc.sznj)
  if(glfsc.sznj>0){
    if(!obj.skqx){
      createMessage.error("应收款需要计算滞纳金，请补充填写收款日期");
    }else{
      skqx = obj.skqx.split(" ")[0];
      console.log(skqx)
       qx = getQx(glfsc.sfyf);
       znj = getZnj(glfsc.rzjs,glfsc.scale,skqx,qx)
       qkje = glfsc.rzjs + znj;

      console.log(glfsc.sznj)
      console.log(skqx)
      console.log(qx)
      console.log(znj)
      console.log(qkje)
    }
  }else{
    qkje = glfsc.rzjs;
  }


  if (!unref(isUpdate)) {
    setFieldsValue({
      grs: glfsc.grs,
      grgl: glfsc.grgl,
      pz1: glfsc.pz1,
      cfgl: glfsc.cfgl,
      cfmj: glfsc.cfmj,
      pz2: glfsc.pz2,
      wfbc: glfsc.wfbc,
      jfbz: glfsc.jfbz,
      pz3: glfsc.pz3,
      cfzj: glfsc.cfzj,
      jfmj: glfsc.jfmj,
      pz4: glfsc.pz4,
      qtfy: glfsc.qtfy,
      pzQt: glfsc.pzQt,
      qkje: qkje,
      skje: qkje,
      qkye: 0,
      c1: glfsc.grgl * glfsc.grs,
      c2: glfsc.cfgl * glfsc.cfmj,
      c3: glfsc.wfbc * glfsc.jfbz,
      c4: glfsc.cfzj * glfsc.jfmj,
      znjbl: glfsc.scale,
      hznj: glfsc.sznj,
      znj: znj,
      bigNum:smalltoBIG(qkje)
    });
  }else{
    setFieldsValue({
      grs: glfsc.grs,
      grgl: glfsc.grgl,
      pz1: glfsc.pz1,
      cfgl: glfsc.cfgl,
      cfmj: glfsc.cfmj,
      pz2: glfsc.pz2,
      wfbc: glfsc.wfbc,
      jfbz: glfsc.jfbz,
      pz3: glfsc.pz3,
      cfzj: glfsc.cfzj,
      jfmj: glfsc.jfmj,
      pz4: glfsc.pz4,
      qtfy: glfsc.qtfy,
      pzQt: glfsc.pzQt,
      c1: glfsc.grgl * glfsc.grs,
      c2: glfsc.cfgl * glfsc.cfmj,
      c3: glfsc.wfbc * glfsc.jfbz,
      c4: glfsc.cfzj * glfsc.jfmj,
      znjbl: glfsc.scale,
      hznj: glfsc.sznj,
      znj: znj,
    });
    updateSchema([{field:"htbh",dynamicDisabled:true},
      {field:"qymc",dynamicDisabled:true},
      {field:"sfyf",dynamicDisabled:true},
      {field:"skqx",dynamicDisabled:true},
      ]);
  }
}
    /** 数字金额大写转换(可以处理整数,小数,负数) */
    function smalltoBIG(n)
    {
      if(!n||n==0)
        return "";
      var fraction = ['角', '分'];
      var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
      var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟']  ];
      var head = n < 0? '欠': '';
      n = Math.abs(n);

      var s = '';

      for (var i = 0; i < fraction.length; i++)
      {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
      }
      s = s || '整';
      n = Math.floor(n);

      for (var i = 0; i < unit[0].length && n > 0; i++)
      {
        var p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++)
        {
          p = digit[n % 10] + unit[1][j] + p;
          n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零')  + unit[0][i] + s;
      }
      return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
    }

    function calculateExt(){
      let obj = getFieldsValue();

      let qkje = obj.qkje;
      let skje = obj.skje?obj.skje:0;
      console.log(obj.skje,smalltoBIG(obj.skje))
      setFieldsValue({qkye:qkje-skje,bigNum:smalltoBIG(obj.skje)});
    }

    function calculateAll(){

      let e={};
      c1(e);
      c2(e);
      c3(e);
      c4(e);
    }

    async function c1(e){
      let obj = getFieldsValue();
      console.log(obj);
      obj.grgl = obj.grgl ? obj.grgl : 0;
      obj.grs = obj.grs ? obj.grs : 0;
      console.log(obj.grgl);
      console.log(obj.grs);
      await setFieldsValue({
        c1: obj.grs * obj.grgl
      }).then(()=>{
        calculateExt();
      })
    }


    function c2 (e){
      let obj = getFieldsValue();
      obj.cfgl = obj.cfgl ? obj.cfgl : 0
      obj.cfmj = obj.cfmj ? obj.cfmj : 0
       setFieldsValue({
        c2: obj.cfgl*obj.cfmj
      }).then(()=>{
         calculateExt();
      })

    };
    function c3 (e){
      let obj = getFieldsValue();
      obj.wfbc = obj.wfbc ? obj.wfbc : 0
      obj.jfbz = obj.jfbz ? obj.jfbz : 0
      setFieldsValue({
        c3: obj.wfbc*obj.jfbz
      }).then(()=>{
        calculateExt();
      })
    };
     function c4(e){
       let obj = getFieldsValue();
       obj.cfzj = obj.cfzj ? obj.cfzj : 0
       obj.jfmj = obj.jfmj ? obj.jfmj : 0
       setFieldsValue({
         c4: obj.cfzj*obj.jfmj
       }).then(()=>{
         calculateExt();
       })
    };


     const minSfyf = ref();

    //表单赋值
    const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
        //重置表单
        await resetFields();
        await getMonRate()
        setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
        isUpdate.value = !!data?.isUpdate;
        if (unref(isUpdate)) {
            //表单赋值
            await setFieldsValue({
                ...data.record,
            });

          const fv = getFieldsValue();

          console.log("------------------",numSplit(fv.skje))
          setFieldsValue({bigNum:smalltoBIG(fv.skje)});

          if(fv && fv.htbh && fv.sfyf && fv.qymc) {
            const params = {qymc:fv.qymc,sfyf:fv.sfyf,htbh:fv.htbh};
            updateGlfsc(fv,params);
          }else{
            resetGlfsc();
          }
        }else{

          updateSchema([{field:"htbh",dynamicDisabled:false},
            {field:"qymc",dynamicDisabled:false},
            {field:"sfyf",dynamicDisabled:false},
            {field:"skqx",dynamicDisabled:false},
          ]);



          updateSchema([ { field: 'htbh', componentProps: { options:[],} },]);
          //console.log(registerForm);
          //const res = await getLsh({});
          const getLsh = '/assets.accountReceive/dbHire/getLsh';
          let params = {};
          const res = await defHttp.get({url: getLsh,params });
          console.log(res);
          await setFieldsValue({
            lsh:res.lsh,
          });
          console.log(userStore)
          setFieldsValue({
            czy:userStore.userInfo.realname,
          });
          //loadDepartList();

      await setFieldsValue({
        skqx:new Date(),
      });

        }


        // 隐藏底部时禁用整个表单
       setProps({ disabled: !data?.showFooter });

        //根据企业名 显示  合同
      updateSchema([
        { field: 'qymc', componentProps: {
            isRadioSelection:true,
          onChange:(d)=>{
              if(!d[0]) {
                updateSchema([{field: 'htbh', componentProps: {options: []}},]);
                resetGlfsc();
                return;
              }

              console.log(d);
              const params = {mc:d,yxzt:'正常'};
              const res =  defHttp.get({url: api.list,params });
              res.then((data)=>{
                console.log(data);
                let option = [];
                for(let i=0;i<data.records.length;i++){
                   option.push({label:data.records[i].ph,value:data.records[i].ph});
                }
                updateSchema([ { field: 'htbh', componentProps: { options:option } },]);
              })



            console.log(d);
            const fv = getFieldsValue();
            console.log(fv);
            if(fv && fv.htbh && fv.sfyf && d[0]) {
              const params = {qymc:d[0],sfyf:fv.sfyf,htbh:fv.htbh};
              updateGlfsc(fv,params);
            }else{
              resetGlfsc();
            }
            },
          } },
        {
          field: 'sfyf',
          componentProps: {
            onChange: (e) => {
              console.log(e);

              if(e.length>0) {
                let str = e.split("-");
                let min = minSfyf.value.split("-");
                console.log(str,min)
                if(str[0]<min[0]){
                  createMessage.warn("不能选择已收款的月份，已重置为"+minSfyf.value);
                  setFieldsValue({sfyf:minSfyf});
                  return;
                }
                if(str[1]<min[1]){
                  createMessage.warn("不能选择已收款的月份，已重置为"+minSfyf.value);
                  setFieldsValue({sfyf:minSfyf.value});
                  return;
                }
              }



              const fv = getFieldsValue();
              console.log(fv);
              if(fv && fv.qymc && fv.htbh && e) {
                const params = {qymc:fv.qymc,sfyf:e,htbh:fv.htbh};
                updateGlfsc(fv,params)
              }else{
                resetGlfsc();
              }
            },
          }
        },
        {
          field: 'htbh',
          componentProps: {
            onChange: (e) => {
              console.log(e);
              const fv = getFieldsValue();
              console.log(fv);

              const params = {qymc:fv.qymc,htbh:e,exp:"0"};
              const res =  defHttp.get({url: apiGlfsc.earliestUnDeal,params });
              res.then((data)=>{
                console.log(data);
                let sfyftemp = fv.sfyf;
                if(data && data.sfyf) {
                  setFieldsValue({sfyf: data.sfyf});
                  sfyftemp = data.sfyf;
                  minSfyf.value = data.sfyf;
                  createMessage.info("当前最早未结清的收款计划的的计收月份为"+sfyftemp);
                }else{
                  createMessage.info("不存在相关的收款计划数据");
                  setFieldsValue({sfyf: null});
                }
                if(fv && fv.qymc && sfyftemp && e) {
                  const params = {qymc:fv.qymc,sfyf:sfyftemp,htbh:e};
                  updateGlfsc(fv,params)
                }else{
                  resetGlfsc();
                }
              })


            },
          }
        },
      ]);



    });
    //设置标题
    const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
    //表单提交事件
    async function handleSubmit(v) {
        try {
            let values = await validate();
            setModalProps({confirmLoading: true});
            //提交表单
            await saveOrUpdate(values, isUpdate.value);
            //关闭弹窗
            closeModal();
            //刷新列表
            emit('success');
        } finally {
            setModalProps({confirmLoading: false});
        }
    }

    async function loadDepartList() {
      const result = await getUserDeparts();
      if (!result.list || result.list.length == 0) {
        return;
      }
      console.log(result)
     // let currentDepart = result.list.filter((item) => item.orgCode == result.orgCode);
      //departList.value = result.list;
    //  departSelected.value = currentDepart && currentDepart.length > 0 ? result.orgCode : '';
     // console.log(result.length)
     // console.log(result[0].tenantId)
     // let dn = result && result.list&&result.list.length > 0 ? result.list[0].tenantId : '';
    //  const res = await getTenantById({id:dn})
     // console.log(res)
     // setFieldsValue({receiver:res.name});
   //   isMultiDepart.value = true;
    }


</script>

<style lang="less" scoped>
	/** 时间和数字输入框样式 */
  :deep(.ant-input-number){
		width: 100%
	}

	:deep(.ant-calendar-picker){
		width: 100%
	}

  *{
  }
  .diyBox{
      border-right: 1px solid #d9d9d9;
      border-bottom: 1px solid #d9d9d9;
      margin-bottom: 20px;
    .row{
      &:last-child{
      }
      display: flex;
    }
  }

  .flex6{
    border-top: 1px solid #d9d9d9;
    border-left: 1px solid #d9d9d9;
    width: 60%;
    display: flex;
    align-items: center;
    
    justify-content: center;
  }
  .flex{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 52px;
  }

  .flex5{
     border-top: 1px solid #d9d9d9;
     border-left: 1px solid #d9d9d9;
     width: 50%;
     display: flex;
     align-items: center;
     justify-content: center;
     flex-wrap: wrap;
      height: 52px;

  }
  .flex4{
     border-top: 1px solid #d9d9d9;
     border-left: 1px solid #d9d9d9;
     width: 40%;
     display: flex;
     align-items: center;
     justify-content: center;
     flex-wrap: wrap;
      height: 52px;

  }
  .flex2{
     border-top: 1px solid #d9d9d9;
     border-left: 1px solid #d9d9d9;
     width: 20%;
     display: flex;
     align-items: center;
     justify-content: center;
      height: 52px;
     flex-wrap: wrap;

  }
  .flex1{
     border-top: 1px solid #d9d9d9;
     border-left: 1px solid #d9d9d9;
     width: 10%;
     display: flex;
     align-items: center;
     justify-content: center;
      height: 52px;

  }
 
</style>
